-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(e2e): add nominal tests for exec & init CLI commands #434
base: master
Are you sure you want to change the base?
Conversation
9425a2f
to
bae3766
Compare
@@ -19,6 +19,7 @@ | |||
"lint": "eslint src test bin scripts", | |||
"test-only": "glob -c \"tsx --test-reporter=spec --test\" \"./test/**/*.spec.ts\"", | |||
"test": "c8 --all --src ./src -r html npm run test-only", | |||
"test:e2e": "glob -c \"tsx --test-reporter=spec --test\" \"./test/commands/*.spec.ts\"", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think functional tests are not executed during development as we expect quick feedback from small unit tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine to have a separate script for e2e tests, however, the glob from existing test-only
script still match e2e tests files.
I think it's simpler to handle this via file names, for instance:
{
"test-only": "glob -c \"tsx --test-reporter=spec --test\" \"./test/**/*.spec.ts\"",
"test:e2e": "glob -c \"tsx --test-reporter=spec --test\" \"./test/**/*.e2e-spec.ts\""
}
} | ||
|
||
export function filterProcessStdout(options, filter): Promise<string[]> { | ||
return new Promise((resolve, reject) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
childprocess was turned into promise in order to collect filtered stdout outputs and emit them all at the end.
test/commands/execute.spec.ts
Outdated
let actualLines: string[] = []; | ||
|
||
try { | ||
actualLines = await filterProcessStdout(options, byMessage); | ||
} | ||
catch (error) { | ||
console.log(error); | ||
|
||
assert.fail("Execute command should not throw"); | ||
} | ||
|
||
assert.deepEqual(actualLines, expectedLines, "we are expecting these lines"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let actualLines: string[] = []; | |
try { | |
actualLines = await filterProcessStdout(options, byMessage); | |
} | |
catch (error) { | |
console.log(error); | |
assert.fail("Execute command should not throw"); | |
} | |
assert.deepEqual(actualLines, expectedLines, "we are expecting these lines"); | |
const actualLines = await filterProcessStdout(options, byMessage); | |
assert.deepEqual(actualLines, expectedLines, "we are expecting these lines"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pas forcément besoin de rendre complexe juste pour un message de failure spécifique
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
const processDir = path.join(__dirname, "..", "fixtures"); | ||
const configFilePath = path.join(processDir, ".nodesecurerc"); | ||
|
||
describe("Report init command", async() => { | ||
beforeEach(async() => await fs.unlink(configFilePath)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Il faudrait plutôt créer la configuration dans le path temp pour ne pas avoir de problèmes avec une modification non-prévu du fichier dans /fixtures
Hi @ErwanRaulo
I don't have this problem, are you sure you built the project first ? |
bae3766
to
1c7450a
Compare
no breaking changes use childprocess to collect CLI stdout missing limit case tests fix NodeSecure#395
@@ -19,6 +19,7 @@ | |||
"lint": "eslint src test bin scripts", | |||
"test-only": "glob -c \"tsx --test-reporter=spec --test\" \"./test/**/*.spec.ts\"", | |||
"test": "c8 --all --src ./src -r html npm run test-only", | |||
"test:e2e": "glob -c \"tsx --test-reporter=spec --test\" \"./test/commands/*.spec.ts\"", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine to have a separate script for e2e tests, however, the glob from existing test-only
script still match e2e tests files.
I think it's simpler to handle this via file names, for instance:
{
"test-only": "glob -c \"tsx --test-reporter=spec --test\" \"./test/**/*.spec.ts\"",
"test:e2e": "glob -c \"tsx --test-reporter=spec --test\" \"./test/**/*.e2e-spec.ts\""
}
import dotenv from "dotenv"; | ||
dotenv.config(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import dotenv from "dotenv"; | |
dotenv.config(); |
Require dotenv
in the script instead ? This way we don't need to import it in multiple files
"test:e2e": "glob -c \"tsx -r dotenv/config --test-reporter=spec --test\" \"./test/commands/*.spec.ts\""
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit picks, this is good job 💪
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
const processDir = path.join(__dirname, "../.."); | ||
|
||
describe("Report execute command", async() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
describe("Report execute command", async() => { | |
describe("Report execute command", () => { | |
} | ||
|
||
const expectedLines = [ | ||
"Executing nreport at: C:\\PERSO\\dev\\report", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Executing nreport at: C:\\PERSO\\dev\\report", | |
`Executing nreport at: ${kProcessDir}`, | |
import dotenv from "dotenv"; | ||
dotenv.config(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import dotenv from "dotenv"; | |
dotenv.config(); | |
Same as above
|
||
// CONSTANTS | ||
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
const processDir = path.join(__dirname, "..", "fixtures"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const processDir = path.join(__dirname, "..", "fixtures"); | |
const kProcessDir = path.join(__dirname, "..", "fixtures"); | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why it's prefixed by k ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a convention for all the constants in all our projects: file-scoped constants should be prefixed with k
, exported constants should be named using CONSTANT_CASE
/UPPER_CASE
, and other constants should be named using camelCase
:)
AFAIK this convention comes from the Google C++ style guide used in Node.js (it's more used for Symbols tho)
Examples:
https://github.com/nodejs/node/blob/main/lib/events.js#L62
https://github.com/nodejs/node/blob/main/lib/events.js#L87
Another example at NodeSecure:
https://github.com/NodeSecure/cli/blob/master/src/http-server/cache.js#L13
// CONSTANTS | ||
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
const processDir = path.join(__dirname, "..", "fixtures"); | ||
const configFilePath = path.join(processDir, ".nodesecurerc"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const configFilePath = path.join(processDir, ".nodesecurerc"); | |
const kConfigFilePath = path.join(processDir, ".nodesecurerc"); | |
const processDir = path.join(__dirname, "..", "fixtures"); | ||
const configFilePath = path.join(processDir, ".nodesecurerc"); | ||
|
||
describe("Report init command", async() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
describe("Report init command", async() => { | |
describe("Report init command", () => { | |
Thanks for feedback, I will correct them all soon. And yes I can run " nreport init " now, don't known if it was thanks to the latest commit or my fault but in my TS migration PR I've used rimraf also. |
TOFIX: could run tests before TS migration, now something goes wrong with childprocess and execution path.
when running nreport init, main process throws the same error :
Error: ENOENT: no such file or directory, open 'C:<yourDevDir>\report\dist\views\template.html'
process try to access views from dist folder but it does not exists, should be added to dist folder as asset in tsconfig file to include a copy when compiling typescript